'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	//event 我的信息 分类     编译类型    内容     图片组  标题  多图展示  创建时刻
	const {user, classify, compiler, content, cover , title, mode, create_time,typesss="是" } = event  // 从客户传过来的值
	
	let article = {
    "author": {
        "author_name": user.author_name,
        "avatar":  user.avatar,
        "id":  user.id,
        "status": user.status
    },
    "browse_count": 0,
    "classify": classify,
    "collection_count": 0,
    "compiler": compiler,
    "comments_count": 0,
    "content": content,
    "cover": cover,
    "create_time": create_time,
    "id": getID(6),
    "mode": mode,
    "thumbs_up_count": 0,
    "title": title,
    "comments": [],
	"typesss":typesss
	}
	
	const add_article = await db.collection('article').add(article)
	
	//返回数据给客户端
	return {
		status: 200,
		msg: '数据添加成功',
		data:add_article
		}
};


// 生成comment_idid值
function getID(length){
	return Number(Math.random().toString().substr(3,length) + Date.now()).toString(36)
}
